package com.sinosoft.cnmuseum.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestDbConn {
	
	static String url = "jdbc:mysql://localhost:3306/dpm_da?"
			+ "useUnicode=true&characterEncoding=UTF-8&useSSL=false";
    static String user = "root";
	static String pwd = "root";
	
	public static void main(String[] args) throws Exception {
		 //加载数据库驱动jdbc
		 Class.forName("com.mysql.jdbc.Driver");  
		 
		 //获取数据库链接，让Java可以操作mysql
		 Connection conn=DriverManager.getConnection(url, user, pwd);
		 //定义一个sql命令
		 String sql="select * from archives_bi limit 1,10"; 
		 //从connection对象中，获取一个sql执行者命名为pr
		 PreparedStatement pr=conn.prepareStatement(sql);
		 //执行
		 ResultSet rs = pr.executeQuery();
		 while(rs.next()){
			 int id = rs.getInt("id");
			 System.out.println(id);
		 }
		 rs.close();
		 //完成操作后关闭数据库链接
		 pr.close();
		 conn.close();
		
	}
}
